//
//  WtfkVC+UI.swift
//  Auscultation
//
//  Created by 来 on 2020/12/7.
//

import Foundation

extension WtfkVC: UITextViewDelegate {
    
    func initUI() {
        
        let top_view = UIImageView.init(image: #imageLiteral(resourceName: "beijing3@1.5x"))
        view.addSubview(top_view)
        top_view.snp.makeConstraints { (make) in
            make.top.left.right.equalToSuperview()
            make.height.equalTo(UIDevice.lgf_NavBarH())
        }
        self.navTitle = "问题反馈"
        self.lgf_NavigationBar.lgf_Title?.textColor = UIColor.white
        
        scrollView = UIScrollView.lgf_Table("FFFFFF")
        if #available(iOS 11.0, *) {
            scrollView.contentInsetAdjustmentBehavior = .never
        } else {
            self.automaticallyAdjustsScrollViewInsets = false
        }
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.top.equalTo(top_view.snp.bottom)
            make.left.right.bottom.equalToSuperview()
        }
        
        wtmc = LGFLoginImageTitleView.init(nil, nil, left: 80, placeholder: "问题名称", text: "", false)
        wtmc.lgf_ViewName = "问题名称"
        wtmc.delegate = self
        scrollView.addSubview(wtmc)
        wtmc.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(10)
            make.height.equalTo(44.lgf_H())
        }
        let label1 = UILabel.init()
        label1.text = "问题名称"
        label1.textColor = UIColor.init(lgf_HexString: "222222")
        label1.font = UIFont.boldSystemFont(ofSize: 16)
        wtmc.addSubview(label1)
        label1.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }

        yzcd = LGFLoginImageTitleView.init(nil, #imageLiteral(resourceName: "icon_arrow"), left: 80, placeholder: "严重程度", text: "", true)
        yzcd.lgf_ViewName = "严重程度"
        yzcd.delegate = self
        scrollView.addSubview(yzcd)
        yzcd.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(wtmc.snp.bottom).offset(10)
            make.height.equalTo(44.lgf_H())
        }
        let label2 = UILabel.init()
        label2.text = "严重程度"
        label2.textColor = UIColor.init(lgf_HexString: "222222")
        label2.font = UIFont.boldSystemFont(ofSize: 16)
        yzcd.addSubview(label2)
        label2.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.bottom.equalToSuperview()
        }

        let label3 = UILabel.init()
        label3.text = "问题描述"
        label3.textColor = UIColor.init(lgf_HexString: "222222")
        label3.font = UIFont.boldSystemFont(ofSize: 16)
        scrollView.addSubview(label3)
        label3.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(yzcd.snp.bottom).offset(10)
            make.height.equalTo(44.lgf_H())
        }
        wtms = UITextView.init()
        wtms.delegate = self
        wtms.font = UIFont.systemFont(ofSize: 16)
        wtms.backgroundColor = UIColor.init(lgf_HexString: "F6F9FB")
        scrollView.addSubview(wtms)
        wtms.snp.makeConstraints { (make) in
            make.top.equalTo(label3.snp.bottom)
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.height.equalTo(200)
        }
        wtms_p = UILabel.init()
        wtms_p.text = "请填写问题"
        wtms_p.textColor = UIColor.init(lgf_HexString: "CFD4D9")
        scrollView.addSubview(wtms_p)
        wtms_p.snp.makeConstraints { (make) in
            make.top.equalTo(label3.snp.bottom).offset(7)
            make.left.equalToSuperview().offset(22)
        }

        let label4 = UILabel.init()
        label4.text = "附件"
        label4.textColor = UIColor.init(lgf_HexString: "222222")
        label4.font = UIFont.boldSystemFont(ofSize: 16)
        scrollView.addSubview(label4)
        label4.snp.makeConstraints { (make) in
            make.width.equalToSuperview().offset(-30)
            make.centerX.equalToSuperview()
            make.top.equalTo(wtms.snp.bottom).offset(10)
            make.height.equalTo(44.lgf_H())
        }

        fj = LGFSelectImageCollectionView.lgf(imageArr: [], addImage: #imageLiteral(resourceName: "fujian@1.5x"), maxCount: 10, cellSize: CGSize.init(width: (UIDevice.lgf_ScreenW - 40) / 4, height: (UIDevice.lgf_ScreenW - 40) / 4 + 5), leftRightSpace: 15, canEdit: true, lineLeft: 1000)
        scrollView.addSubview(fj)
        fj.delegate = self
        fj.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.width.equalToSuperview()
            make.top.equalTo(label4.snp.bottom)
            make.height.equalTo((UIDevice.lgf_ScreenW - 40) / 4 + 5)
        }
        
        let button1 = UIButton.init(type: .custom)
        button1.backgroundColor = UIColor.init(lgf_HexString: EWEDarkMode.c_0F88F2)!
        button1.setTitle("确定", for: .normal)
        button1.setTitleColor(EWEDarkMode.white(), for: .normal)
        button1.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button1.layer.cornerRadius = 4
        button1.layer.masksToBounds = true
        button1.addTarget(self, action: #selector(WtfkVC.queding(_:)), for: .touchUpInside)
        scrollView.addSubview(button1)
        button1.snp.makeConstraints { (make) in
            make.top.equalTo(fj.snp.bottom).offset(30)
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-75)
            make.height.equalTo(44)
        }
        
        let button2 = UIButton.init(type: .custom)
        button2.setTitle("取消", for: .normal)
        button2.setTitleColor(UIColor.init(lgf_HexString: EWEDarkMode.c_0F88F2)!, for: .normal)
        button2.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button2.layer.cornerRadius = 4
        button2.layer.masksToBounds = true
        button2.layer.borderColor = UIColor.init(lgf_HexString: EWEDarkMode.c_0F88F2)!.cgColor
        button2.layer.borderWidth = 1.0
        button2.addTarget(self, action: #selector(WtfkVC.quxiao(_:)), for: .touchUpInside)
        scrollView.addSubview(button2)
        button2.snp.makeConstraints { (make) in
            make.top.equalTo(button1.snp.bottom).offset(15)
            make.centerX.equalToSuperview()
            make.width.equalToSuperview().offset(-75)
            make.height.equalTo(44)
        }
        
        scrollView.lgf_AutoContentSize(0)
    }
    
    func textViewDidChange(_ textView: UITextView) {
        wtms_p.isHidden = textView.text.count > 0
    }

}

extension WtfkVC: LGFLoginImageTitleViewDelegate {
    func selectLGFLoginImageTitleView(_ view: LGFLoginImageTitleView) {
        self.view.endEditing(true)
        if view.lgf_ViewName == "严重程度" {
            let picker = LGFBottomPickerView()
            let data = ["一般", "严重"]
            let sindex = data.lgf_IndexOfObject(self.yzcd.textField.text ?? "一般")
            picker.showIn(self.view, data, sindex) { [weak self] (view, name, index) in
                self?.yzcd.textField.text = data[index]
                self?.yzcd.lgf_Name = index.description
            }
        }
    }
}

extension WtfkVC: LGFSelectImageCollectionViewDelegate {
    func selectImageCollectionViewCount(view: LGFSelectImageCollectionView, imageArr: [UIImage]) {
        let height = ((UIDevice.lgf_ScreenW - 40) / 4 + 5) * ceil(CGFloat(imageArr.count + 1) / 4.0)
        view.snp.updateConstraints { (make) in
            make.height.equalTo(height)
        }
        scrollView.lgf_AutoContentSize(0)
        EWERequest.uploadFile(imageArr, "0", "image") { [weak self] (url) in
            self?.fj.lgf_Name = url
        } _: { (error) in
            SVProgressHUD.showError(error)
        }
    }
}
